package com.stt.design.voice;

import com.stt.base.model.Device;
import com.stt.base.service.DeviceService;
import com.stt.design.mediator.DeviceMediator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 语音命令处理器
 */
@Component
public class VoiceCommandProcessor {
    
    @Autowired
    private DeviceService deviceService;
    
    @Autowired
    private DeviceMediator deviceMediator;
    
    /**
     * 处理语音命令
     */
    public void processCommand(VoiceCommand command) {
        switch (command.getType()) {
            case "DEVICE":
                processDeviceCommand(command);
                break;
            case "SCENE":
                processSceneCommand(command);
                break;
        }
    }
    
    private void processDeviceCommand(VoiceCommand command) {
        Device device = deviceService.getDeviceByName(command.getTarget());
        if (device != null) {
            switch (command.getAction()) {
                case "on":
                    deviceService.controlDeviceStatus(device.getId(), true);
                    break;
                case "off":
                    deviceService.controlDeviceStatus(device.getId(), false);
                    break;
                case "set":
                    deviceService.controlDeviceParameter(
                        device.getId(), 
                        Integer.parseInt(command.getValue())
                    );
                    break;
            }
        }
    }
    
    private void processSceneCommand(VoiceCommand command) {
        if ("execute".equals(command.getAction())) {
            deviceMediator.executeScene(command.getTarget());
        }
    }
} 